package com.evan.webadmin.utils;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.io.File;

/**
 * MyBatisPlus代码生成器
 * 3.5.0
 */
public class MyBatisPlusGenerator {

    public static void main(String[] args) {
        //表名，多个英文逗号分割
        String outputDir = System.getProperty("user.dir") + File.separator + "application-webadmin/src/main/java";

        String moduleName = "biz";
        String packagePath = "com.evan.webadmin";
        // 代码生成器
        new AutoGenerator(new DataSourceConfig
                .Builder("jdbc:mysql://106.15.182.221:3066/custom_train?characterEncoding=utf8&useSSL=true&serverTimezone=Asia/Shanghai", "root", "shzl@123abcd")
                .build()
        )
                .global(new GlobalConfig.Builder()
                        .outputDir(outputDir)
                        .author("Pavel")
                        .openDir(false)
                        //.enableSwagger()
                        .dateType(DateType.ONLY_DATE)
                        .fileOverride()
                        .build()
                )
                .packageInfo(new PackageConfig.Builder()// 包配置
                        .parent(packagePath)
                        .moduleName(moduleName)
                        .controller("controller")
                        .entity("model")
                        .service("service")
                        .serviceImpl("service.impl")
                        .mapper("dao")
                        .xml("dao.mapper")
                        .build()
                )
                .strategy(new StrategyConfig.Builder()// 策略配置
                        .enableCapitalMode()// 全局大写命名
                        //.addExclude("databasechangelog", "databasechangeloglock")// 排除生成的表 sys_user
                        .addInclude("biz_evluate_record") // 对应表 sys_user
                        .addTablePrefix("biz") // 表前缀
                        // .addFieldPrefix("tb_") // 字段前缀
                        //.enableSkipView() //跳过视图
                        .controllerBuilder()
                        .enableRestStyle() //@RestController 注解
                        .enableHyphenStyle() //url中驼峰转连字符
                        // .superClass(IBaseController.class)
                        .formatFileName("%sController")

                        .entityBuilder()
                        .enableLombok()// lombok 模型
                        .enableChainModel() // 链式操作
                        .enableSerialVersionUID()
                        // .enableRemoveIsPrefix() 去掉字段前边的is
                        //.superClass(BaseModel.class)
                        //.addSuperEntityColumns("createTime", "createBy", "updateTime", "updateBy", "deleteFlag") // 自定义实体，公共字段
                        .naming(NamingStrategy.underline_to_camel)
                        .enableTableFieldAnnotation()
                        .serviceBuilder()
                        .formatServiceFileName("I%sService")
                        .formatServiceImplFileName("%sServiceImpl")
                        .mapperBuilder()
                        .formatMapperFileName("%sMapper")
                        .enableBaseResultMap()
                        .enableBaseColumnList()
                        .build()
                ).execute();
    }

}

